"""
这个类封装了使用polars对SQL SERVER数据库的直接操作
"""
from util import ip
import connectorx as cx

class SQLServer_polars:
    def __init__(self,database):
        self.server = ip
        self.database = database
        self.username = 'sa'
        self.password = 'cj126414.'
        self.conn = f"mssql://{self.username}:{self.password}@{self.server}/{self.database}"

    def query(self, sql):
        try:
            # 创建连接并执行查询
            df = cx.read_sql(self.conn, sql, return_type="polars")
            return df
        except Exception as e:
            print(f"Error executing query: {e}")
            return 0